﻿using System.Text;
using System.Web.UI;
using JQuery.WebKit.Base;
using JQuery.WebKit.WebCommon;

namespace JQuery.WebKit
{
    public class JMessage : WebControlBase
    {
        public string Text { get; set; }
        public JMessageType MessageType { get; set; }
        public JMessage()
            : base("div")
        {
        }

        protected override void Render(HtmlTextWriter writer)
        {
            string html = Text;
            if (string.IsNullOrWhiteSpace(html))
            {
                html = this.Controls.GetInnerHtml();
            }
            if (string.IsNullOrWhiteSpace(html))
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            string cssType = string.Empty;
            switch (MessageType)
            {
                case JMessageType.Info:
                    cssType = "ui-icon-info";
                    break;
                case JMessageType.Warn:
                    cssType = "ui-icon-notice";
                    break;
                case JMessageType.Error:
                    cssType = "ui-icon-alert";
                    break;
                default:
                    break;
            }

            sb.AppendLine("<div class='ui-widget'>");
            sb.AppendLine("<div style='padding: 0pt 0.7em;' class='ui-state-highlight ui-corner-all'> ");
            sb.AppendLine("<p>");
            sb.AppendFormat("<span style='float: left; margin-right: 0.3em;' class='ui-icon {0}'></span>", cssType);
            sb.AppendLine(html);
            sb.AppendLine("</p>");
            sb.AppendLine("</div>");
            sb.AppendLine("</div>");

            writer.Write(sb.ToString());
        }
    }
}
